So you wanna ray trace huh?
Well before that, and before you start looking at the example DM, we need to get our mindset ready on exactly what we're working with.

First, create an imaginary 3d universe (in your head, not in avs).  We'll call this universe Bill.  Bill has an origin, x,y,and z axes, and it stretches infinitely in all directions, just like any good 3d universe should.  Picture these things. Bill is what the viewer of your preset will be looking at through his AVS window.  The origin, axes, and universe are anchored in place.  All other things move relative to these.  If you imagine yourself looking at this from different angles, it's you who's rotated and moved to see these new angles, not the universe.  Now imagine a pyramid with a square base. It should probably be near the origin, so you can imagine movements.  Have it move around and rotate in your head.  Again, it is rotating relative to the origin, not the other way around.

What does this pyramid represent? The square base of the pyramid represents a portal between our universe and Bill.  It is commonly referred to as the AVS window.  The tip of the pyramid is they eye of some unknown person in our universe watching Bill through this portal.  When the portal moves a foot away from the origin, the viewer, his chair, the room he's in, his grandmother, Richard Simmons, and everything else in the viewer's universe moves a foot away from Bill's origin.  Whenever you are working on a ray traced DM, you do not see what's happening from the viewpoint of the person looking through the portal.  You are always watching from a fixed position relative to the origin, and you are always visualizing the view pyramid moving and rotating relative to the origin.

I've been very repetitive in describing the above situation.  This is just because it is VITAL to look at things this way.  Really, once you have the situation pictured, the math isn't that complicated.  So if you're getting confused, just come back to this part and make sure you're looking at things the right way.

OK, time to start looking at the actual DM coding. We'll start with ox, oy, and oz.

ox = the x coordinate of the eye of the viewer aka the tip of the pyramid.
oy = y coordinate of eye
oz = z coordinate of eye

so the location of the eye is (ox,oy,oz).  If you want the viewer to see bill from a different location, change these.  Simple, right?

The example DM has created the plane z=1.  So picture a plane one unit down the z axis.  Set all the variables in the frame section of the example DM to zero.  I just had different values to show that the DM actually was creating a plane.  Now change ox, oy, and oz in the frame section of the example DM by small increments. changing ox and oy slides the pyramid left/right and up/down the plane, while oz moves the pyramid closer to or farther away from the plane.  If you don't have a picture in your mind of what is going on here then you're helpless.

Next variables: dx, dy, and dz.

(k*dx,k*dy,k*dz) describes a line passing through the origin.  We will ignore negative k values, so this describes a ray originating at the origin.  For every distance dx that a point moves on the x axis, it must move dy on the y axis and dz on the z axis, so as k becomes larger and larger, the point moves farther and farther in a straight line away from the origin.  We don't want to trace rays moving from the origin though: we want to trace rays moving from the tip of the pyramid, so we use (k*dx+ox,k*dy+oy,k*dz+oz).  This just slides the start of the ray over to the top of the pyramid and otherwise leaves it the same.  So now when we put the code:

dx1=x;
dy1=y;
dz1=1; 

in the pixel box, we are describing a ray that originates from (ox,oy,oz) and per every 1 unit on the z axis it moves x units on the x axis and y units on the y axis.  If k=1 for all of these points, then they will all move one unit on the z axis and describe the base of the pyramid.

Now we get to xa, ya, and za.

If you understand 3d Superscopes, then the code

dx2=dx1*cos(za)+dy1*sin(za);
dy2=dy1*cos(za)-dx1*sin(za);
dy3=dy2*cos(xa)+dz1*sin(xa);
dz2=dz1*cos(xa)-dy2*sin(xa);
dz3=dz2*cos(ya)+dx2*sin(ya);
dx3=dx2*cos(ya)-dz2*sin(ya);

already is very familiar to you. xa is the rotation around the x axis, ya is rotation around y axis, and za is rotation around z axis, all in radians.  If you fiddle with these values in the per frame section of the DM by adding small increments to each one (increments of 0.1 radians) you should understand the rotation around the various axes.  So when we take (k*dx+ox,k*dy+oy,k*dz+oz) and change it to (k*dx3+ox,k*dy3+oy,k*dz3+oz), we are 

1. describing the rays (using dx, dy, and dx)
2. rotating the rays around the origin (using cx, cy, and cz to alter dx, dy, and dz)
3. shifting the start of the rays to the top of the pyramid (using ox, oy, and oz)

This is all quite simple, right?

then on to the variable ik!

In the explanations above, we have used k as a general variable that really could be anything.  But now we want to find a specific k.  This is the k at which our rays intersect the surface we are tracing.  When you're looking at most other people's DMs, ik will just be called k, but I'm using ik here to clarify that this is the value of k that intersects the surface.  For this example we are using the plane z=1, as was stated previously.  So:

                z  =  1
     	ik*dz3+oz  =  1
           ik*dz3  =  1-oz
               ik  =  (1-oz)/dz3

We just substitute (ik*dx3+ox) for x, (ik*dy3+oy) for z, and (ik*dz3+oz) for z, and then solve for k using algebra.  For a simple plane this was easy, although more complicated shapes have more complicated formulas that can involve frustrating factoring.  This is why most people have stuck with planes, cylinders, and spheres.

Great! now that we have ik we can find ix, iy, and iz! we're practically done!

The code for ix, iy, and iz is:

ix=ik*dx3+ox3;
iy=ik*dy3+oy3;
iz=ik*dz3+oz3;

boy, doesn't this look familiar.  where've we seen that equation before? anyways, to summarize so far, we

1. describe the rays (using dx, dy, and dz)
2. rotate the rays around the origin (using cx, cy, and cz to modify dx, dy, and dz)
3. shift the start of the rays to the top of the pyramid (using ox, oy, and oz)
4. find the value for k at which the ray intersects the surface (using substitution and some algebra)
5. plug ik into the standard formula to get x, y, and z values for the intersection point.

Down to the last two steps! first step is to texture your surface with x and y.  I just used

x=ix;
y=iy;

which seems kinda redundant.  Why did I bother explaining it this way, and how does it work?  In this preset we are telling the computer that "when the x coordinate of the pixel equals 101.1 and the y coordinate equals 47.3 USING BILL'S COORDINATE SYSTEM, then the color of the pixel equals the current color of the pixel at (101.1,47.3) USING THE AVS WINDOW'S COORDINATE SYSTEM.  (you didn't forget about bill, did you?)  The computer registers (101.1,47.3) as (1.1,1.3) because wrap is on. so

====================================================================
|Bill's x coordinate            |  -5  ------------------------> 5 |
====================================================================
|x coordinate of color of pixel |  -1 -> 1                         |
|			        |       -1 --> 1                   |
|			        |	      -1 --> 1             |
|                               |                   -1 --> 1       |
|			        |		    	  -1 --> 1 |
====================================================================

because with wrap enabled whenever the value gets over 1 it immediately jumps back down to -1.  So as bill's x stretches ten units deep, it cycles through the original image 5 times.  Same for y.  I explained it this way because you might want to do it differently for different shapes.  For example, for a circle that has been extruded down the z axis (i.e. a cylinder) we would use

x=atan2(iy,ix);
y=iz

this is because atan2(iy,ix) is the angle (r) around bill's z axis.  We want to use the angle because we need to wrap the original image around the cylinder.  This is the best that I can explain the texturing.

woohoo! last step! alpha blending! and this one's simple.

remember waaaaaay back near the beginning?  I said that we would discard negative k values.  All we need to do is blend all ik values below zero out.

alpha=above(ik,0);

if we kept the negative ik values then the viewer wouldn't just see the plane if it were in front of him : he would see it behind him too.  See UnConeD's explanation to understand this better.

and it is finished!

oh yeah, fix the aspect ratio.